package com.infore.exchange.main.dao;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.infore.common.model.entity.exchange.Services;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * Hadoop集群服务 Mapper 接口
 * </p>
 *
 * @author lijh
 * @since 2023-05-15
 */
@Mapper
@Component
public interface ServicesMapper extends BaseMapper<Services> {


    /**
     * 查询各服务的进程
     * @return
     */
    @Select("select s.SERVICE_ID,s.NAME as SERVICE_NAME,s.SERVICE_TYPE,\n" +
            "       r.ROLE_ID, r.name as ROLE_NAME,r.ROLE_TYPE ,\n" +
            "       r.HOST_ID,r.CONFIGURED_STATUS,\n" +
            "       p.NAME as  PROCESSES_NAME,p.COMMAND_ID,\n" +
            "       h.IP_ADDRESS,h.NAME AS HOST_NAME,\n" +
            "       p.PROCESS_USER,p.RUN_GENERATION,p.STATUS_LINKS,\n" +
            "       c.NAME as COMMAND_NAME,c.STATE,c.ACTIVE,c.RESULT_MESSAGE,c.SUCCESS\n" +
            "from SERVICES s\n" +
            "left join ROLES  r on s.SERVICE_ID= r.SERVICE_ID\n" +
            "left join PROCESSES  p on r.ROLE_ID= p.ROLE_ID\n" +
            "left join HOSTS h on r.HOST_ID = h.HOST_ID\n" +
            "left join COMMANDS c on p.COMMAND_ID = c.COMMAND_ID\n" +
            "where s.CLUSTER_ID is not null\n" +
            "and r.CONFIGURED_STATUS!='NA'\n" +
            "order by s.SERVICE_ID")
    List<Map<String, Object>> queryServiceProcess();
}
